<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
    <link type="text/css" href="http://resource.afrous.net/ext-2.1/resources/css/ext-all.css" rel="stylesheet" />
    <script type="text/javascript" src="http://resource.afrous.net/ext-2.1/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="http://resource.afrous.net/ext-2.1/ext-all.js"></script>
		<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAYtWO2s_klJQZgGk9oArIARRmI3lB2kIhUEg2LASOZZIDjc2UtxSi-S1m6g3ouXwpfDHENivN6HGNMg"></script>
    <script type="text/javascript">
google.load("maps", "2.x");
google.load('friendconnect', '0.8');
google.setOnLoadCallback(startGFC);

var map;
function startGFC() {
  google.friendconnect.container.setNoCache(1);
  google.friendconnect.container.setParentUrl('/svn/trunk/');
  google.friendconnect.container.initOpenSocialApi({
    site: '05678604299044637748',
    onload: init
  });
}

function init() {

  var frames = {};
  gadgets.rpc.register("pubsub", function(type, service, data) {
    if (type == 'subscribe') {
    console.log(this);
    console.log(arguments);
      frames[service] = (frames[service] || []).concat(this.f)
    } else if (type == 'publish') {

      map.panTo(new google.maps.LatLng(data.lat, data.lng));

      var ifrs = frames[service];
      console.log(ifrs);
      for (var i=0; i<ifrs.length; i++) {
        var ifrId = ifrs[i];
        gadgets.rpc.call(ifrId, "pubsub", null, type, service, data);
      } 
    }
  });

  /*
  gadgets.rpc.register("resize_iframe", function() {
    console.log(arguments);
  });
  */

  new Ext.Window({
    id : 'gadgetA',
    x : 100, y : 100,
    width : 300, height : 300,
    collapsible : true,
    resizable : true,
    listeners : {
      render : function() {
    google.friendconnect.container.renderOpenSocialGadget({
      id : this.body.dom.id,
      url : 'http://hackathon-jp.googlecode.com/svn/trunk/OpenSocial20090424/RPC/gadgetA-gfc.xml',
      site: '05678604299044637748'
    });
      }
    }
  }).show();

  new Ext.Window({
    id : 'gadgetB',
    x : 900, y : 100,
    width : 300, height : 300,
    collapsible : true,
    resizable : true,
    listeners : {
      render : function() {
    google.friendconnect.container.renderOpenSocialGadget({
      id : this.body.dom.id,
      url : 'http://hackathon-jp.googlecode.com/svn/trunk/OpenSocial20090424/RPC/gadgetB-gfc.xml',
      site: '05678604299044637748'
    });
      }
    }
  }).show();

  new Ext.Window({
    id : 'People',
    x : 500, y : 100,
    width : 300, height : 300,
    collapsible : true,
    resizable : true,
    listeners : {
      render : function() {
    google.friendconnect.container.renderOpenSocialGadget({
      id : this.body.dom.id,
      url : 'http://hackathon-jp.googlecode.com/svn/trunk/OpenSocial20090424/RPC/People.xml',
      site: '05678604299044637748'
    });
      }
    }
  }).show();


  var v = new Ext.Viewport({
    layout : 'border',
    items : [{
      region : 'north',
      height : 40,
      listeners : {
        render : function(p) {
          google.friendconnect.renderSignInButton({ id : p.body.id });
        }
      } 
    }, {
      id : 'gmap',
      region : 'center',
      html : '<div id="map" style="width:100%;height:100%" />',
      listeners : {
        render : function(p) {
          setTimeout(function() {
            map = new google.maps.Map2(document.getElementById('map'));
            map.setCenter(new google.maps.LatLng(35.689649,139.694338), 15);
          }, 1000);
        }
      }
    }]
  });

}
</script>
<style type="text/css">
</style>
	</head>
	<body>
	</body>
</html>

